package eval.engine;

import com.google.inject.Inject;
import eval.deploy.IDemandManager;
import eval.deploy.IDeployManager;
import eval.engine.FireFighting.FireFightingEngine;
import eval.engine.cplex.cplexEngine;
import eval.engine.openStack.OpenStackEngine;
import eval.host.IHostManager;
import eval.host.compare.ISortHostList;
import eval.hostEvaluate.IHostEvaluate;
import eval.vm.IVMManager;

/**
 * this class creates the engine model according 
 * to the current engine running in the experiment.
 * 
 * @author Amit Peled   <amit.kapina@gmail.com>
 * @author Igal Kaufman <igal.kaufman@gmail.com>
 */ 
public class PlacementEngineFactory implements IplacementEngineFactory {

	private IVMManager vmManager;
	private IDeployManager deployManager;
	private IHostManager hostManager;
	private IDemandManager demandManager;
	private IHostEvaluate hostEvaluator;
	private ISortHostList sortHostList;


	/**
	 * create the engine.
	 * 
	 * @Constructor
	 * @param vmManager 
	 * @param deployManager
	 * @param hostManager
	 * @param demandManager
	 * @param sortHostList
	 * @param hostEvaluator
	 */
	@Inject
	public PlacementEngineFactory(IVMManager vmManager,
			IDeployManager deployManager, IHostManager hostManager,
			IDemandManager demandManager,ISortHostList sortHostList,
			IHostEvaluate hostEvaluator) {
		this.vmManager = vmManager;
		this.deployManager = deployManager;
		this.hostManager = hostManager;
		this.demandManager = demandManager;
		this.sortHostList = sortHostList;
		this.hostEvaluator = hostEvaluator;

	}
	
	/* (non-Javadoc)
	 * @see eval.engine.IplacementEngineFactory#createNewEngine(java.lang.String)
	 */
	@Override
	public IPlacementEngine createNewEngine(String engineStr) {
		OptimizationGoalEnum engine = OptimizationGoalEnum.valueOf(engineStr);
		switch (engine) {
		case OPEN_STACK:
			return new OpenStackEngine(vmManager, deployManager, hostManager, demandManager,
					sortHostList, hostEvaluator);
		case CPLEX:
			return new cplexEngine(vmManager, deployManager, hostManager, demandManager,
					sortHostList, hostEvaluator);
			
		case FIRE_FIGHTING:
			return new FireFightingEngine(vmManager, deployManager, hostManager, demandManager,
					sortHostList, hostEvaluator);
		default:
			throw new IllegalArgumentException("Invalid placement engine");
		
		}
	}
}
